var List = [];
import Mock from "mockjs";
import { param2Obj } from '../utils/urlUtils'
for (var i = 0; i < 100; i++) {
    var indexR = Mock.mock('@natural(0, 3)')
    List.push({
        id: Mock.mock('@id()'),
        bianhao: Mock.mock('@id'),
        weixin: Mock.mock('@last()'),
        shouji: Mock.mock(/^1[3456789]\d{9}$/),
        kecheng: indexR,
        jine: indexR,
        zhuangtai: Mock.mock('@natural(1, 5)'),
        shijian: Mock.mock('@datetime()')
    })
}

let object2 = JSON.parse(JSON.stringify(List));


export default {
    getorderData: config => {
        console.log('获取的config', config);
        var { keyword, page, pageSize } = param2Obj(config.url)
        console.log(page, pageSize);
        var res = List.filter(item => item.shouji.indexOf(keyword) != -1)
        var resLimit = res.filter((item, index) => {
            return (page - 1) * pageSize <= index && index < page * pageSize
        })
        return {
            code: 200,
            msg: '订单页面请求成功',
            data: resLimit,
            total: List.length
        }
    },

    delssqq: config => {
        console.log("删除的config", config);
        console.log('config', JSON.parse(config.body));
        var { id } = JSON.parse(config.body)
        var res = List.filter(item => item.id != id)
        List = res
        return {
            code: 200,
            msg: '订单删除成功',
            data: null
        }
    },
    MoreDeleteById: (config) => {
        var { ids } = JSON.parse(config.body)
        List = List.filter(item => !ids.includes(item.id))
        return {
            code: 200,
            mag: '订单批量删除成功',
            data: null
        }
    },
    typeByIds: (config) => {
        List = object2
        var { id } = JSON.parse(config.body)
        List = List.filter(item => item.zhuangtai == id);
        if (id == 0) {
            List = object2
        }
        return {
            code: 200,
            mag: '订单切换成功',
            data: null
        }
    },
}